package com.netted.studentbook.activity;

import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.blankj.utilcode.util.BarUtils;
import com.mylhyl.superdialog.SuperDialog;
import com.netted.studentbook.R;
import com.netted.studentbook.constant.Constant;
import com.netted.studentbook.http.HttpRequest;
import com.netted.studentbook.sharedPreferences.SharedPreferencesHelper;

/**
 * Created by lu on 2018/6/22.
 */

public class BaseActivity extends AppCompatActivity {
    SharedPreferencesHelper sharedPreferencesHelper = null;

    HttpRequest request = null;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BarUtils.setStatusBarVisibility(this,false);
        sharedPreferencesHelper= new SharedPreferencesHelper(this, Constant.XML_NAME);
        request = new HttpRequest();
    }


    public void showDialog(String title,String content,SuperDialog.OnClickPositiveListener listener){
        new SuperDialog.Builder(this).setRadius(20)
                .setAlpha(1).setCancelable(false)
                .setTitle(title).setMessage(content)
                .setPadding(200,100,200,100)
                .setPositiveButton("确定", listener).build();
    }


    public void playSound(Context cxt,int resId){
        MediaPlayer mediaPlayer = MediaPlayer.create(cxt, resId);
        //设置播放起始点
        mediaPlayer.seekTo(0);
        //开始播放
        mediaPlayer.start();

        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                mediaPlayer.stop();
                mediaPlayer = null;
            }
        });
    }
}
